package com.pubinfo.passbook.engine.process.variable.medicine;

import com.pubinfo.passbook.common.model.dto.witeoff.MedicineOnJobOrRetireDTO;
import com.pubinfo.passbook.common.model.ruler.PayInformation;
import com.pubinfo.passbook.common.service.ruler.CheckService;
import com.pubinfo.passbook.common.utils.ApplicationContextUilts;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.List;

/**
 * 所有自费+自理总和
 *
 * @author zhouch
 * @date 2022/1/10 11:10
 */
@Slf4j
public class AllAmountSelfProcessor extends MedicineVariableProcessor {


    CheckService ruleService;

    public AllAmountSelfProcessor() {
        ruleService = ApplicationContextUilts.getBean(CheckService.class);
    }

    @Override
    public BigDecimal get(MedicineOnJobOrRetireDTO data) {

        log.info("执行参数处理器: {}", this.getClass().getSimpleName());

        List<PayInformation> payInformations = cache.getPayInformationData();
        BigDecimal sumAllAmountSelfs = BigDecimal.ZERO;
        BigDecimal sumAmountSelfs = BigDecimal.ZERO;

        for (PayInformation payInformation : payInformations) {

            //获取自费项目总数
            BigDecimal sumAmountSelf = ruleService.sumAmountSelf(payInformation.getDetailsList());
            //计算
            if (sumAmountSelf.equals(new BigDecimal(-0.0000999))) {
                cache.markNeedAudit();
                log.info("{} ==> 需要人工审核.", getClass().getName());
                sumAmountSelf = BigDecimal.ZERO;
            }
            sumAmountSelfs = sumAmountSelfs.add(sumAmountSelf);


            BigDecimal selfpaymentCost = payInformation.getSelfpaymentCost();
            //计算
            if (selfpaymentCost.equals(new BigDecimal(-0.0000999))) {
                cache.markNeedAudit();
                log.info("{} ==> 需要人工审核.", getClass().getName());
                selfpaymentCost = BigDecimal.ZERO;
            }
            sumAllAmountSelfs = sumAmountSelfs.add(selfpaymentCost);

        }

        log.info("参数处理器: {} 结果: {}", this.getClass().getSimpleName(), sumAllAmountSelfs);

        return sumAllAmountSelfs;
    }
}
